package com.fs.sys.service;

import com.fs.common.exception.AppException;
import com.fs.sys.bean.dto.SysFileDTO;
import com.fs.common.ErrorCodes;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件上传服务
 *
 * @author  LiuQi 2025/4/7-9:45
 * @version V1.0
 **/
public interface FileUploadService {
    /**
     * 文件上传
     */
    default SysFileDTO upload(String module, MultipartFile file) {
        String fileName = file.getOriginalFilename();
        try {
            return this.upload(module, fileName, file.getBytes());
        } catch (IOException e) {
            throw AppException.of(ErrorCodes.BASE_FILE_UPLOAD_FAILED);
        }
    }

    SysFileDTO upload(String module, String fileName, byte[] bytes);

    byte[] getContent(String objectName);
}
